import axios from 'axios'
const fetchCates = (params = {}) => {
  return axios.get('https://api.it120.cc/conner/cms/category/list', {params})
}
export default {
  namespace: 'count',
  state: {
    num: 0,
    cates: []
  },
  reducers: {
    add(state: any, action: any) {
      console.log(action);
      
      state.num += action.num;
      return {
        ...state
      }
    },
    initCates (state, action) {
      console.log(action);
      state.cates = action.data
      return {
        ...state
      }
    }
  },
  // 做异步操作
  /* 
    利用是 
  */
  effects: {
    *getCates(action: any, {call, put }: any) {
      console.log(action);
      
      const res = yield call(fetchCates, action.params)
      console.log(res);
      // put dispatch 一个 action 触发普通reducer
      if (res.data.code === 0) {
        yield put({ type: 'initCates', data: res.data.data });
      }
     
      
      // yield put({ type: 'add' });
    },
  },
};
        